﻿using System;
using System.Net;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Linq.Expressions;

using System.ComponentModel;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.ComponentModel.DataAnnotations;
using UIElement = System.Windows.UIElement;

namespace Fayshine.VA.Helpers
{
    public abstract class EntityManager<T> 
        where T : new()
    {
        public PagedObservableCollectionView<T> Results { get; private set; }
        public EntityManager()
        {
            Results = new PagedObservableCollectionView<T>();
        }

        //public IEnumerable<KeyValuePair<string, System.Windows.UIElement>> SupportedFilterEditors
        //{
        //    get
        //    {
        //        foreach (PropertyInfo p in typeof(T).GetProperties())
        //        {
        //            DisplayAttribute a = p.GetCustomAttributes(true).FirstOrDefault(t => t is DisplayAttribute) as DisplayAttribute;
        //            if (a != null && a.GetAutoGenerateFilter()==true)
        //            {
        //                if (p.PropertyType == typeof(string))
        //                {
        //                    yield return new KeyValuePair<string, System.Windows.UIElement>(p.Name, new Common.View.FilterUIOfString() { FilterByProperty = p.Name });
        //                }
        //                else if (p.PropertyType == typeof(bool))
        //                {
        //                    yield return new KeyValuePair<string, System.Windows.UIElement>(p.Name, new Common.View.FilterUIOfBool() { FilterByProperty = p.Name });
        //                }
        //                else if (p.PropertyType == typeof(int))
        //                {
        //                    yield return new KeyValuePair<string, System.Windows.UIElement>(p.Name, new Common.View.FilterUIOfInt() { FilterByProperty = p.Name });
        //                }
        //            }
        //        }
        //    }
        //}

        public IEnumerable<KeyValuePair<string, Type>> SupportedFilterFields
        {
            get
            {
                foreach (PropertyInfo p in typeof(T).GetProperties())
                {
                    DisplayAttribute a = p.GetCustomAttributes(true).FirstOrDefault(t => t is DisplayAttribute) as DisplayAttribute;
                    if (a != null && a.GetAutoGenerateFilter() == true)
                    {
                        yield return new KeyValuePair<string, Type>(p.Name, p.PropertyType);
                    }
                }
            }
        }


        public virtual T CreateDevice() { return new T(); }

    }


}
